
typedef struct
{
	unsigned int writePointer;
	unsigned int readPointer;
	unsigned int parsePointer;
	char * buffer;
	unsigned int bufferSize;
	unsigned int maximumSize;
} dualfifo_t;

typedef enum
{
	DUALFIFO_MODE_WRITE,  //! Write
	DUALFIFO_MODE_READ,   //! Read from read pointer
	DUALFIFO_MODE_PARSE,  //! Parse pointer
	DUALFIFO_MODE_BOTH    //! Read and update both the parse and read pointers
} dualfifo_mode;

/** Initialises the dualfifo structure and allocates memory.
  *  initialSize initial size of the FIFO buffer to allocate.  The buffer size will be increased in
  *    multiples of initialSize.
  *  maximumSize maximum size the buffer is allowed to grow to before refusing more data.  -1 for unlimited
  */
int dualfifo_new( dualfifo_t * fifo, unsigned int initialSize, unsigned int maximumSize ); 

/** Frees all memory associated with the buffer */
void dualfifo_free( dualfifo_t *fifo );

/** Returns the number of bytes available for a given operation as specified by the mode parameter.
  */
int dualfifo_bytesAvailable( dualfifo_t *fifo, dualfifo_mode mode );

/** Writes the data given to the end of the FIFO.
  * 
  * The function will return the number of bytes written.  If size bytes cannot be written to the FIFO,
  *  because the buffer size cannot be increased further (due to max size being reached), no bytes will be
  *  written and the function will return 0.
  */
int dualfifo_write( dualfifo_t *fifo, const void * data, unsigned int size );

int dualfifo_peek( dualfifo_t *fifo, dualfifo_mode readMode, void * data, unsigned int size );

int dualfifo_advance( dualfifo_t *fifo, dualfifo_mode readMode, unsigned int size );

int dualfifo_read( dualfifo_t *fifo, dualfifo_mode readMode, void * data, unsigned int size );



